﻿@model Consumer.Models.CourseViewModel

@{
    ViewBag.Title = Model.Course.Name;
}

<h2>@ViewBag.Title</h2>

<div>
    <h4>Course</h4>
    <hr />

    <div class="col-md-offset-1">
        <dl class="dl-horizontal">
            <dt>Instructor</dt>
            <dd>@Model.Course.Instructor.FullName</dd>
            <dt>Enrollment</dt>
            <dd>
                @Html.Action("Enroll", new { courseId = Model.Course.CourseId })
            </dd>
        </dl>
        <p>
            @if (User.IsInRole(Consumer.Models.UserRoles.TeacherRole) && Model.Course.Instructor.Id == ViewBag.UserId)
            {
                @Html.ActionLink("Edit", "Edit", new { id = Model.Course.CourseId })
                <text> | </text>
            }
            @Html.ActionLink("Back to List", "Index")
        </p>
    </div>
    <hr />
</div>

<div>
    <h4>Assignments</h4>
    <hr />

    <div class="col-md-offset-1">
        @if (!Model.Course.Assignments.Any())
        {
            <p>There are no assignments yet.</p>
        }
        else
        {
            <table class="table">
                <tr>
                    <th>Assignment</th>
                    <th>Provider</th>
                    @if (Model.Course.EnrolledUsers.Any(u => u.Id == ViewBag.UserId))
                    {
                        <th>Your Score</th>
                    }
                    else
                    {
                        <th></th>
                    }
                    <th></th>
                </tr>

                @foreach (var assignment in Model.Course.Assignments)
                {
                    @Html.Action("CourseAssignment", new { id = assignment.AssignmentId })
                }
            </table>
        }
        @if (User.IsInRole(Consumer.Models.UserRoles.TeacherRole) && Model.Course.Instructor.Id == ViewBag.UserId)
        {
            <p>
                @Html.ActionLink("Create Assignment", "Create", "Assignment", new { Model.Course.CourseId }, null)
                @Html.Action("ContentItemTools", new { Model.Course.CourseId })
            </p>
        }
    </div>
    <hr />
</div>

@if (User.IsInRole(Consumer.Models.UserRoles.TeacherRole) && Model.Course.Instructor.Id == ViewBag.UserId)
{
    <div>
        <h4>Gradebook</h4>
        <hr />
        
        <div class="col-md-offset-1">
            @Html.Action("CourseGradebook", new { id = Model.Course.CourseId })
        </div>
    </div>
}
